package com.third.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.third.entity.Brand;
import com.third.entity.R;
import com.third.service.Brand_service;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 谢添发
 * @version 1.1
 * @date 2023/10/23 14:16
 */
@RestController
@RequestMapping("/brand")
public class Brand_Controller {
    @Resource
    private Brand_service brandService;

    @PostMapping("/save")
    public void saveBrand(Brand brand){
        brandService.save(brand);
    }

    @DeleteMapping("/delete")
    public void deleteBrandById(int id){
        brandService.removeById(id);
    }

    @PutMapping("/update")
    public void updateBrand(Brand brand){
        brandService.updateById(brand);
    }

    @GetMapping("/page")
    public R getPage(@PathVariable int currentPage, @PathVariable int size ,Brand brand){
        Page<Brand> page = new Page<>(currentPage, size);
        QueryWrapper<Brand> wrapper = new QueryWrapper<>();
        wrapper.eq("id",brand.getBrandId()).eq("name",brand.getBrandName())
                .eq("origin",brand.getOrigin()).eq("degree",brand.getDegree())
                .eq("price",brand.getPrice()).eq("warehouse",brand.getWarehouse());
        Page<Brand> Ipage = brandService.page(page, wrapper);
        return new R(true,Ipage.getRecords());
    }
    @GetMapping("/list")
    public R getList(){
        List<Brand> list = brandService.list();
        return new R(true,list);
    }
}
